/**
 * @param {string[][]} items
 * @param {string} ruleKey
 * @param {string} ruleValue
 * @return {number}
*/
var countMatches = function(items, ruleKey, ruleValue) {
  let index = 0, result = 0;
  if(ruleKey == 'color') index = 1;
  else if(ruleKey == 'name') index = 2;
  for(let i = 0; i < items.length; i++) {
    if(items[i][index] == ruleValue) result++;
  }
  return result;
};
let items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver";
console.log(countMatches(items, ruleKey, ruleValue));
items = [["phone","blue","pixel"],["computer","silver","phone"],["phone","gold","iphone"]], ruleKey = "type", ruleValue = "phone";
console.log(countMatches(items, ruleKey, ruleValue));
